package com.zhufeng.materialdesign.ui;

import android.content.Intent;
import android.support.design.widget.CollapsingToolbarLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.MenuItem;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.zhufeng.materialdesign.R;

public class AnimalActivity extends AppCompatActivity {

    public static final String ANIMAL_NAME="animal_name";
    public static final String ANIMAL_IMAGE_ID="animal_image_id";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_animal);
        //获取跳转传值
        Intent intent=getIntent();
        String animalName=intent.getStringExtra(ANIMAL_NAME);
        int animalImageId=intent.getIntExtra(ANIMAL_IMAGE_ID,0);
        //初始化控件
        Toolbar toolbar= (Toolbar) findViewById(R.id.animal_toolbar);
        CollapsingToolbarLayout collapsingToolbarLayout= (CollapsingToolbarLayout) findViewById(R.id.collapsing_toolbar);
        ImageView animalImageView= (ImageView) findViewById(R.id.animal_image_view);
        TextView animalContentText= (TextView) findViewById(R.id.animal_content_text);
        //设置内容
        setSupportActionBar(toolbar);
        ActionBar actionBar=getSupportActionBar();
        if(actionBar!=null){
            actionBar.setDisplayHomeAsUpEnabled(true);
            actionBar.setHomeAsUpIndicator(R.drawable.back);
        }
        collapsingToolbarLayout.setTitle(animalName);
        Glide.with(this).load(animalImageId).into(animalImageView);
        String animalContent=generateAnimalContent(animalName);
        animalContentText.setText(animalContent);

    }
    //创建显示内容
    private String generateAnimalContent(String animalName) {
        StringBuilder animalContent=new StringBuilder();
        for (int i=0;i<300;i++){
            animalContent.append(animalName);
        }
        return animalContent.toString();
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()){
            case android.R.id.home:
                finish();
                return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
